<template>
	<view v-if="pageShow">
		<view class="mainpadding_top ffffff flexleft" @click="contactshow=true">
			<u-icon name="plus-circle-fill" size="20" color="#3478f5"></u-icon>
			<view class="margin_left xiaolan main_size">加客服微信</view>
		</view>
		<view class="mainpadding_top ffffff">
			<view class="flexbetween">
				<view class="titletext xiaohei bold">{{dataAll.title}}</view>
				<view class="titletext xiaohong bold">{{dataAll.score}}</view>
			</view>
			<view class="flexbetween margin_top xiaohui main_size">
				<view class="">数量：{{dataAll.num}}</view>
				<view class="">{{dataAll.createtime_text}}</view>
			</view>
			<view class="datibox margin_top6">
				<view class="xiaohei main_size">认真答题，如实回答！</view>
				<view class="xiaohei main_size margin_top1" style="word-break: break-all;">{{url2}}</view>
			</view>
			<view class="submitbtn margin_top6" @click="sharewx" v-if="dataAll.type!=2">点击分享</view>
			<view class="flexaround margin_top6">
				<view class="flexcenter" @click="back">
					<u-icon name="grid" size="20" color="#3478f5"></u-icon>
					<view class="margin_left1 xiaolan main_size">更多任务</view>
				</view>
				<view class="flexcenter" @click="zhijiedt()">
					<u-icon name="fingerprint" size="20" color="#3478f5"></u-icon>
					<view class="margin_left1 xiaolan main_size">直接答题</view>
				</view>
			</view>
			<view class="mainpadding_top ffffff">
				<view class="flexbetween">
					<view class="main_size bold xiaohei">邀请成功答题人数</view>
					<view class="main_size  xiaohei">{{dataAll.int_success_num}}</view>
				</view>
				<!-- <view class="flexbetween margin_top">
					<view class="main_size bold xiaohui">退回</view>
					<view class="main_size  xiaohui">0</view>
				</view> -->
				<view class="flexbetween margin_top">
					<view class="main_size bold xiaohei">预计收益</view>
					<view class="main_size bold xiaohong">{{dataAll.int_success_score}}</view>
				</view>
				<view class="datibox margin_top6 flexaround">
					<view class="xiaolan main_size" @click="lookmobile">查看手机号</view>
					<!-- <view class="xiaolan main_size" @click="show=true">查看手机号</view> -->
					<view class="xiaolan main_size" @click="getdetail">刷新</view>
				</view>
			</view>
		</view>
		<u-popup :show="contactshow" @close="contactshow=false" :round="20">
			<view class="mainpadding">
				<view class="xiaohei flexcenter titletext margin_top">联系客服</view>
				<view class="flexcenter margin_top">
					<image :src="dataAll.kf_image" style="width:300rpx;height:300rpx;" mode=""></image>
				</view>
				<view class="xiaohei main_size margin_top6 textcenter">扫描上方二维码添加客服微信</view>
			</view>
		</u-popup>
		<u-modal :show="show" title="查看手机号" confirmText="关闭" @confirm="show=false">
			<view class="slot-content mainpadding2" style="min-width: 550rpx;">
				<scroll-view scroll-y="true" style="max-height: 400rpx;">
					<view class="xiaohui main_size margin_top textcenter" v-if="dataAll.success_list.length==0">暂无
					</view>
					<view class="flexbetween margin_top" v-for="(item,index) in dataAll.success_list" :key="index">
						<view class="flexleft">
							<u-icon name="phone" size="20" color="#3478f5"></u-icon>
							<view class="xiaohei main_size">{{item.userinfo.phone}}</view>
						</view>
						<view class="xiaohong main_size bold">{{item.score}}</view>
					</view>
				</scroll-view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				contactshow: false,
				listid: "",
				shareurl: "",
				url2: "",
				dataAll: {},
				shareAll: {},
				pageShow: false,
				show: false,
				urlId: ""
			}
		},
		onLoad(options) {
			this.listid = options.id
			console.log(this.listid);
			this.getdetail()
		},
		methods: {
			lookmobile() {
				uni.navigateTo({
					url: "/pages/index/lookmobile?id=" + this.listid
				})
			},
			sharewx() {
				let that = this
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 0,
					href: that.shareurl,
					title: that.shareAll.share_title,
					summary: that.shareAll.share_des,
					imageUrl: that.shareAll.share_logo,
					success: function(res) {
						console.log("success:" + JSON.stringify(res), "分享成功");
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err), "分享失败");
					}
				});
			},
			getdetail() {
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				httpRequest.request('/api/user/tmDetail', 'GET', {
					id: this.listid
				}).then(res => {
					if (res.code == 1) {
						this.dataAll = res.data
						console.log(res.data);
						if (this.pageShow == false) {
							this.getdata()
						} else {
							uni.hideLoading()
						}
					} else {
						uni.hideLoading()
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			back() {
				uni.navigateBack(1)
			},
			getdata() {
				let _this = this;
				httpRequest.request('/api/index/getConfigInfo', 'GET', {}).then(res => {
					if (res.code == 1) {
						uni.hideLoading()
						let url2 = ""
						if (this.dataAll.type == 1) {
							let url = this.dataAll.tsurveyLink.substring(0, this.dataAll.tsurveyLink.length - 5) +
								uni
								.getStorageSync("user_id")
							let reg1 = new RegExp("amp;", "g"); // 加'g'，删除字符串里所有的"amp"
							url2 = url.replace(reg1, "");
						}
						if (this.dataAll.type == 2 || this.dataAll.type == 3) {
							let url = this.dataAll.tsurveyLink
							let reg1 = new RegExp("amp;", "g"); // 加'g'，删除字符串里所有的"amp"
							url2 = url.replace(reg1, "");
						}
						if (this.dataAll.type == 3) {
							let url = this.dataAll.tsurveyLink + "&userid=" + this.dataAll.id +
								'ac96a9df980b4605a4e2301713c74c51' + uni
								.getStorageSync("user_id");
							let reg1 = new RegExp("amp;", "g"); // 加'g'，删除字符串里所有的"amp"
							url2 = url.replace(reg1, "");
						}
						if (this.dataAll.type == 7) {
							let url = this.dataAll.tsurveyLink.replace('[%%pid%%]', uni
								.getStorageSync("user_id"))
							let reg1 = new RegExp("amp;", "g"); // 加'g'，删除字符串里所有的"amp"
							url2 = url.replace(reg1, "");
						}
						this.url2 = url2
						this.shareAll = res.data
						this.pageShow = true
						if (this.dataAll.type == 9) {
							this.getOtherurl()
						}else{
							this.getcodeId()
						}
					}
				})
			},
			getOtherurl() {
				httpRequest.request('/api/user/getZampliaUrl', 'GET', {
					id: this.listid
				}).then(res => {
					this.url2 = res.data.url
					this.getcodeId()
				}).catch(err => {
					console.log(err);
				})
			},
			getcodeId() {
				let data = {
					url: this.url2
				}
				if(this.dataAll.type==9){
					this.$set(data,"type",2)
					this.$set(data,"tm_id",this.listid)
					this.$set(data,"user_id",uni.getStorageSync("user_id"))
				}
				httpRequest.request('/api/index/addShareData', 'GET', data).then(res => {
					console.log(res);
					if (res.code == 1) {
						this.shareurl = this.shareAll.share_url + '?code=' + uni.getStorageSync("invite_code") +
							"&tourl=" + res.data + "&type=" + this.dataAll.type
						console.log(this.shareurl);
					}
				}).catch(err => {
					console.log(err);
				})
			},
			zhijiedt() {
				plus.runtime.openURL(this.url2)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.datibox {
		background-color: #f5f7fb;
		padding: 15rpx;
		border-radius: 5rpx;
	}
</style>